// Vector.cpp

// Implementacia vektora

#include "Common/World/Vector.h"
#include "Common/World/Point.h"
#include <math.h>

// Nastavi a vypocita dlzku vektora a uhol, ktory zviera s X-ovou osou 
void Vector::AdjustAng()
{
	if(ySize == 0)
	{
		if(xSize < 0)
		{
			length = -xSize;
			angle = DegAngle(180);
		}
		else
		{
			length = xSize;
			angle = DegAngle(0);
		}
	}
	else if(xSize == 0)
	{
		if(ySize < 0)
		{
			length = -ySize;
			angle = DegAngle(-90);
		}
		else
		{
			length = ySize;
			angle = DegAngle(90);
		}
	}
	else
	{
		length = sqrtf(xSize * xSize + ySize * ySize);
		angle = RadAngle(atan2f(ySize, xSize));
	}
}

// Nastavi a vypocita x-ovu a y-ovu velkost vektora
void Vector::AdjustXY()
{
	// Ak je dlzka vektora = 0, nastav parametre vektora vsetky na 0
	if(length == 0)
	{
		angle = DegAngle(0);
		xSize = ySize = 0;
		return;
	}
	// Ak je dlzka vektora < 0 (opacne orientovany vektor), zmeni u nej znamienko, uhol zvacsi o 180
	else if(length < 0)
	{
		length = -length;
		angle += DegAngle(180);
	}
	
	xSize = length * angle.Cos();
	ySize = length * angle.Sin();
}
